import { Exporter } from "..";

export default class PhpExporter implements Exporter {
    public readonly id = crypto.randomUUID()
    public readonly name = 'PHP'
    private static readonly SUFFIX = '.php'

    export(data: Array<TranslateTaskResult>){
        const transferMaps:Record<string, string> = {}
        data.forEach(({ locale, data }) => {
            transferMaps[locale + PhpExporter.SUFFIX] = this.createCode(data)
        })
        return transferMaps
    }

    createCode(data: Array<PacketData>){
        let content = '<?php\n\nreturn [\n'
        data.forEach(item => {
            for(let key in item.data){
                content += '\t' + JSON.stringify(key) + ' => ' + JSON.stringify(item.data[key]) + ',\n'
            }
        })
        content = content.slice(0, -2)
        content += '\n];\n'
        return content
    }
}
